<template>
	<view>
		<view class="form bgfff">
			<view class="form-item flex-ac">
				<text class="label">真实姓名</text>
				<view class="right-input flex-ac flex1">
					<input type="text" v-model="formData.name" disabled placeholder="请输入您的真实姓名"
						placeholder-class="plStyle" />
				</view>
			</view>
			<view class="form-item flex-ac">
				<text class="label">客户号</text>
				<view class="right-input flex-ac flex1">
					<input type="text" v-model="formData.customerNum" disabled placeholder="请输入您的客户号"
						placeholder-class="plStyle" />
				</view>
			</view>
			<view class="form-item flex-ac">
				<text class="label">身份证</text>
				<view class="right-input flex-ac flex1">
					<input type="text" v-model="formData.identityCode" disabled placeholder="请输入您的身份证"
						placeholder-class="plStyle" />
				</view>
			</view>
			<view class="form-item flex-ac">
				<text class="label">手机号码</text>
				<view class="right-input flex-ac flex1">
					<input type="text" v-model="formData.phone" disabled placeholder="请输入您的手机号码"
						placeholder-class="plStyle" />
				</view>
			</view>
		</view>
		<view class="saveBtn" @tap="handleSumbit"
			v-if="isReal&&formData.status==1">确认无误</view>
		<view class="saveBtn" @tap="handleReal" v-if="!isReal&&apiFinish">实名认证</view>
		<view class="saveBtn" v-if="formData.status==2" @tap="goLook">查看合同</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formData: {},
				isReal: false, //谁否实名了
				apiFinish:false,
			}
		},
		onLoad() {
			if(this.vuex_userInfo){
				this.formData = JSON.parse(this.vuex_userInfo)
				console.log('formData', this.formData);
				this.getAuth()
			}
		},
		methods: {
			goLook(){
				this.$u.to('/pages/index/contractSuccess?customerNum='+this.formData.customerNum+'&productCode='+this.formData.productCode)		
			},
			handleSumbit() {
				if(this.formData.is_client!='true') return this.$u.msg('您不是有效客户！')
				if(this.formData.clientStatus!=1) return this.$u.msg('您的账户异常！')
				uni.showLoading({
					title:'加载中...'
				})
				this.$http.get(`/api/h5/f/batch/create/sign`, {
					customerNum: this.formData.customerNum,
					iDCardNum: this.formData.identityCode,
					name: this.formData.name,
					phone: this.formData.phone,
					productCode: this.formData.productCode,
					productName: this.formData.productName,
					termValidity: this.formData.termValidity
				}).then(res => {
					if (res.data.code == 200) {
						let result = res.data.data
						console.log('查询合同', result)
						if (result.code == 0) {
							let url = result.data.batchSignUrlWithoutLogin
							let params = encodeURIComponent(url)
							uni.hideLoading()
							this.$u.to('/pages/webview/webview?url=' + params, 'redirectTo')
						} else {
							this.$u.msg(result.msg)
						}
					} else {
						this.$u.msg(res.data.msg)
					}
				})
			},
			handleReal() { //去实名返回i链接
				this.$http.post(`/api/h5/d/auth`, {
					customerNum: this.formData.customerNum,
					identityCode: this.formData.identityCode,
					name: this.formData.name,
					phone: this.formData.phone
				}).then(res => {
					if (res.data.code == 200) {
						let result = res.data.data
						console.log('实名认证链接', result)
						let url = result.authUrl
						let params = encodeURIComponent(url)
						this.$u.to('/pages/webview/webview?url=' + params, 'redirectTo')
					} else {
						this.$u.msg(res.data.msg)
					}
				})
			},
			getAuth() { //查询是否实名认证过
				this.$http.get(`/api/h5/c/psnInfo`, {
					customerNum: this.formData.customerNum
				}).then(res => {
					let result = res.data
					console.log('是否实名', result)
					if (res.data.code == 200) {
						this.isReal = true
					} else if (res.data.code == 1450910) {
						this.isReal = false
					} else {
						this.$u.msg(res.data.msg)
					}
					this.apiFinish = true
				})
			},
			getLeval() { //

			},
		}
	}
</script>

<style lang="less">
	.form {
		padding: 10rpx 30rpx;

		.form-item {
			padding: 20rpx 0;
			border-bottom: 1px solid #f6f7f8;

			&:last-child {
				border: none;
			}

			.label {
				width: 160rpx;
			}
		}
	}

	.saveBtn {
		margin: 80rpx 60rpx 30rpx 60rpx;
		height: 85rpx;
		border-radius: 15rpx;
	}
</style>